package crm8000.Controllers

import crm8000.Models.FId;
import crm8000.Models.GoodsUnit;
import crm8000.services.BizLogService;
import crm8000.services.FidService
import crm8000.services.GoodsService
import crm8000.services.MainMenuService
import crm8000.services.PermissionService
import crm8000.services.RecentFidService;
import crm8000.services.UserService;
import grails.converters.JSON

class GoodsController {
	
	def PermissionService permissionService

	static allowedMethods = [allUnits: "POST", editUnit: "POST"]

	def UserService userService
	
	def GoodsService goodsService

	def goodsUnitIndex() {
		if (!permissionService.hasPermission("1002")) {
			redirect controller: "home"
		}
		
		[loginUserName: userService.loginUserName]
	}
	
	def allUnits() {
		def data = goodsService.allUnits()
		
		JSON.use("deep")
		def json = new JSON(data)
		json.setIncludes(GoodsUnit.class, ["unitId", "name"])
		
		render json
	}
	
	def editUnit() {
		def result = goodsService.editUnit(params)
		
		render result as JSON
	}
	
	def deleteUnit() {
		def result = goodsService.deleteUnit(params.unitId)
		
		render result as JSON
	}
}
